package com.youthburin.base.services;

import java.io.Serializable;
import java.util.List;

import org.springframework.data.domain.Sort;

import com.youthburin.base.springjpa.MyRepository;
import com.youthburin.base.util.DwzPagination;

public abstract class AbstractService<T, ID extends Serializable> implements BaseService<T, ID> {

	public abstract MyRepository<T, ID> getMyRepository();

	@Override
	public void dwzFindAll(DwzPagination dwzPagination) {
		getMyRepository().dwzFindAll(dwzPagination);
	}

	@Override
	public List<T> findAll() {
		return getMyRepository().findAll();
	}

	@Override
	public List<T> findAll(Sort sort) {
		return getMyRepository().findAll(sort);
	}

	@Override
	public T save(T t) {
		return getMyRepository().save(t);
	}

	@Override
	public T update(T t) {
		return getMyRepository().update(t);
	}

	@Override
	public void delete(List<ID> idList) {
		if (idList != null && !idList.isEmpty()) {
			for (ID id : idList) {
				getMyRepository().delete(id);
			}
		}
	}

	@Override
	public void delete(ID id) {
		getMyRepository().delete(id);

	}

	@Override
	public void delete(T t) {
		getMyRepository().delete(t);
	}

	@Override
	public T get(ID id) {
		return getMyRepository().findOne(id);
	}

	@Override
	public boolean exists(ID id) {
		return getMyRepository().exists(id);
	}

}
